import java.util.Arrays;
import java.util.Scanner;

/**
 * 【程序30】   
 * 题目：有一个已经排好序的数组。现输入一个数，要求按原来的规律将它插入数组中。
 */
public class test30 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        System.out.println("原数组为：" + Arrays.toString(array));
        System.out.print("请输入一个数，程序将为其插入数组中：");
        int number = sc.nextInt();
        int max = 0;
        int[] newArray = Arrays.copyOf(array, array.length + 1);
        for (int i = 0; i < 10; i++) {
            max = newArray[i];
            if (max >= number) {
                for (int j = newArray.length - 2; j >= i; j--) {
                    newArray[j + 1] = newArray[j];
                }
                newArray[i] = number;
                break;
            } else if (i == 9) {
                newArray[10] = number;
                break;
            }
        }
        System.out.println("插入后数组为：" + Arrays.toString(newArray));
    }
}
